<?php
class Zendvn_Captcha_Image extends Zend_Captcha_Image{
	
	public function __construct($arrParam = null, $options = null){
		parent::__construct();
		//$captcha = new Zend_Captcha_Image();
		$this->setImgDir(FILE_PATH . '/captcha/img');
		$this->setImgUrl(FILE_URL . '/captcha/img' );
		$this->setWidth(300);
		$this->setHeight(150);
		$this->setFont(FILE_PATH . '/captcha/font/PLANETBE.TTF');
		$this->setFontSize(36);
		$this->setWordlen(4);
		$this->generate();
		//Luu vao session duoc tao ra boi Captcha
		$namespace = 'Zend_Form_Captcha_' . $this->getId();
		$ssCaptcha = new Zend_Session_Namespace($namespace);
		$ssCaptcha->word = $this->getWord();
		//$this->view->captchaID = $captcha->getId();		
		
	}
	
	public function removeCaptchaImg(){
	
		$directory = $this->getImgDir();
		
		$arrFolder = scandir($directory);
		$captchaImg = $this->getId() . $this->getSuffix();
		$pattern = '#^(\.|\.\.|' . $captchaImg .')$#';
		foreach ($arrFolder as $val){
			if(!preg_match($pattern, $val)){
				$filename = $this->getImgDir() . '/' . $val;
				unlink($filename);
			}
		}
	}
}